/*
 * @Author: fhw
 * @Date: 2022-08-02 14:38:35
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-01-29 16:22:24
 * @Description:
 */
import { ApiProperty } from '@nestjs/swagger';
import { ChatUser } from 'src/chat_user/entities/chat_user.entity';
import { GroupChat } from 'src/group-chat/entities/group-chat.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { PaginatedResult } from '../../common/entities/entities';

@Entity('group-chat-record')
export class GroupChatRecord {
  @ApiProperty({ example: 'id', description: 'id' })
  @PrimaryGeneratedColumn({
    type: 'int',
    comment: 'id',
  })
  id: number;

  @ApiProperty({ example: 'content', description: '消息内容' })
  @Column({
    type: 'longtext',
    comment: '消息内容',
  })
  content: string;

  @ApiProperty({ example: 'date', description: '创建时间' })
  @CreateDateColumn({
    type: 'datetime',
    comment: '创建时间',
  })
  createDate: string;

  @ApiProperty({ example: 'updateDate', description: '更新时间' })
  @UpdateDateColumn({
    type: 'datetime',
    comment: '更新时间',
  })
  updateDate: string;

  @ApiProperty({
    example: 'type',
    description: '文本类型：1是普通文本，2是图片，3是语音',
  })
  @Column({
    type: 'tinyint',
    comment: '文本类型：1是普通文本，2是图片，3是语音',
    default: 1,
  })
  type: number;


  @ApiProperty({ example: 'userId', description: '用户id' })
  @Column({
    type: 'int',
    comment: '用户id',
  })
  userId: number;

  @ManyToOne(() => ChatUser, (user) => user.id, { eager: true })
  @JoinColumn({ name: 'userId' })
  user: ChatUser

  @ApiProperty({ example: 'group_id', description: '群id' })
  @Column({
    type: 'int',
    comment: '群id',
    nullable: true,
  })
  group_id: string;

  @ManyToOne(() => GroupChat, (groupChat) => groupChat.group_id)
  @JoinColumn({ name: 'group_id' })
  groupChat: GroupChat;

}
export class GroupChatRecordResult extends PaginatedResult {
  @ApiProperty({
    example: GroupChatRecord,
    type: [GroupChatRecord],
  })
  data: GroupChatRecord[];
  @ApiProperty({ example: 'pageSize', description: '数量' })
  pageSize: number;
  @ApiProperty({ example: 'pageNum', description: '页数' })
  pageNum: number;
  @ApiProperty({ example: 'total', description: '总数' })
  total: number;
}
